package com.roadmap.struts.action.admin.msg;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.roadmap.biz.message.NoticeManager;
import com.roadmap.cache.RdcSessionCache;
import com.roadmap.struts.action.ActionConst;
import com.roadmap.struts.action.RdcAction;

public class NoticeAction extends RdcAction {

	public NoticeAction() {
		super("getnotice");
	}

	@Override
	public ActionForward performAction(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		String ownerId = getUIDFromSession(request);
		NoticeManager noticeMgr = new NoticeManager(ownerId);
		List notices = noticeMgr.getNoticesFromFriends();
		if (notices != null && !notices.isEmpty()) {
			request.setAttribute("notices", notices);

			// after the notice data was loaded, set the request count stored
			// in session to 0
			RdcSessionCache cache = (RdcSessionCache) request.getSession()
					.getAttribute(ActionConst.RDC_SESSION_CACHE_NAME);
			cache.setNoticeCount(0);
		}
		return mapping.findForward("getnotice");
	}

	@Override
	public boolean isFormSubmitted(HttpServletRequest request) throws Exception {
		return false;
	}
}
